<template>
    <div class="dashboard-container">
        <div v-show="showFlag">
            <my-search :fields="fieldsList" :baseNumber="12" @onSearch="searchForm" @onReset="resetForm" :selectIsAddAll="false"></my-search>
           
            <div class="table-list">
                <my-table v-loading="loading" ref="myEltable" style="width: 100%" row-key="id" :showsummary="false" :columns="tableColumns" :tableData="tableDatas" :pageNum="queryObj.pageNo" :pageSize="queryObj.pageSize" :height="$store.state.app.windowHeight - 180" max-height="660px" :current="false" @onCurrentChange="changepageNo" @onPageSizeChange="changePageSize" :totalPage="total" highlight-current-row :ifSelect="false" />
            </div>
        </div>
       
    </div>
</template>

<script>

import { queryPageList, statistics, exportData } from '@/api/cxtj/zdsygl'
import { hylx } from '@/api/common'
import { downloadFile } from "@/utils/utils"
export default {
    name: 'zdsygl-list',

    data() {
        return {
            loading: false,
            tjloading: false,
            showFlag: true,
            fieldsList: [
                {
                    label: '纳税人名称',
                    field: 'nsrmc',
                    type: 'text',
                    value: ''
                },
                {
                    label: '纳税人识别号',
                    field: 'nsrsbh',
                    type: 'text',
                    value: ''
                },
               
             
             
                
                 {
                    label: '年度范围',
                    field: 'date',
                    type: 'yearrange', // daterange
                    value: [],
                    options: [
                        {
                            field: 'ksnd',
                            value: ''
                        },
                        {
                            field: 'jsnd',
                            value: ''
                        }
                    ],
                    change: value => {
                        // this.changxm(value);
                    }
                },
               
               {
                    label: '税种',
                    field: 'hyml_mc',
                    type: 'select',
                    value: [],
                    multiple: true,
                    options: [
                        {label:'资产负债表',value:'1'},
                        {label:'现金流量表',value:'2'},
                        {label:'利润表',value:'3'},
                    ],
                    change: (value) => {
                    }
                },

            ],

            tableColumns: [
                {
                    label: '企业名称',
                    prop: 'nsrmc',
                    align: 'center',
                    minWidth: 200
                },
                {
                    label: '企业识别号',
                    prop: 'nsrmc',
                    align: 'center',
                    minWidth: 200
                },
                {
                    label: '所属地市',
                    prop: 'ssds',
                    align: 'center',
                    minWidth: 200
                },
                {
                    label: '企业类型',
                    prop: 'qylx',
                    align: 'center',
                    minWidth: 200
                },
                {
                    label: '税种',
                    prop: 'sz',
                    align: 'center',
                    minWidth: 200
                },
                {
                    label: '所属期起',
                    prop: 'nsrsbh',
                    align: 'center',
                    minWidth: 200
                },
               
                {
                    label: '所属期止',
                    prop: 'hyml_mc',
                    align: 'center',
                    minWidth: 200
                },

                 {
                    label: '申报金额(万元)',
                    prop: 'sbje',
                    align: 'center',
                    width: 150
                },
                {
                    label: '入库金额(万元)',
                    prop: 'rkje',
                    align: 'center',
                    width: 150
                },
                





            ],

            tableDatas: [],
            ruleForm: {
                hyml_mc: false,
                hdml_mc: false,
                hzml_mc: false,
                hxyml_mc: false,
                sssf: false,
                ssds: false,
                zgswjg_mc: false
            },
            tjtableData: [],
            queryObj: {
                nsrmc: '', //公司名称
                nsrsbh: '',
                nsrzt: '',
                hyml_mc: '',
                hydl_mc: '',
                hyzl_mc: '',
                hyxl_mc: '',
                sfjw: '',
                sssf: '',
                ssds: '',
                zgswjg_dm: '',


                pageNo: 1,
                pageSize: 20
            },
            total: 0,

        }
    },

    mounted() {
       
    },
    methods: {

        searchForm(params) {
            this.queryObj.nsrmc = params.nsrmc || ''
            this.queryObj.nsrsbh = params.nsrsbh || ''
            this.queryObj.nsrzt = params.nsrzt || ''
            this.queryObj.hyml_mc = params.hyml_mc ? this.checkParams(3, params.hyml_mc) : ''
            this.queryObj.hydl_mc = params.hydl_mc ? this.checkParams(4, params.hydl_mc) : ''
            this.queryObj.hyzl_mc = params.hyzl_mc ? this.checkParams(5, params.hyzl_mc) : ''
            this.queryObj.hyxl_mc = params.hyxl_mc ? this.checkParams(6, params.hyxl_mc) : ''
            this.queryObj.sfjw = params.sfjw || ''
            this.queryObj.ssds = params.ssds ? this.checkParams(9, params.ssds) : ''
            this.queryObj.sssf = params.sssf || ''
            this.queryObj.zgswjg_dm = params.zgswjg_dm || ''

            this.getTableData();
        },
        checkParams(index, str) {
            let arrList = this.fieldsList[index].options
            for (let i = 0; i < arrList.length; i++) {
                if (arrList[i].value == str) {
                    return arrList[i].label
                }
            }
        },
        resetForm() {
            for (let key in this.queryObj) {
                if (key == 'pageNo') {
                    this.queryObj[key] = 1;
                } else if (key == 'pageSize') {
                    this.queryObj[key] = 20;
                } else {
                    this.queryObj[key] = '';
                }
            }
            // this.tableDatas = []
            // this.total = 0

        },
        getTableData() {
            this.loading = true
            let params = {
                nsrmc: this.queryObj.nsrmc,
                nsrsbh: this.queryObj.nsrsbh,
                nsrzt: this.queryObj.nsrzt,
                hyml_mc: this.queryObj.hyml_mc,
                hydl_mc: this.queryObj.hydl_mc,
                hyzl_mc: this.queryObj.hyzl_mc,
                hyxl_mc: this.queryObj.hyxl_mc,
                sfjw: this.queryObj.sfjw,
                sssf: this.queryObj.sssf,
                ssds: this.queryObj.ssds,
                zgswjg_dm: this.queryObj.zgswjg_dm,


                pageNum: this.queryObj.pageNo,
                pageSize: this.queryObj.pageSize,
                qylx_dm: 11,
                sfzb: 'N'
                // sfssgs: this.queryObj.sfssgs ? 'Y' : '',
                // jtxxk: this.queryObj.jtxxk ? 'Y' : '',
            }
            queryPageList(params).then(res => {
                this.loading = false
                if (res.code == 200) {
                    this.tableDatas = res.data.records
                    this.total = res.data.total
                }
            })
        },
      




        changepageNo(currPage) {
            this.queryObj.pageNo = currPage;
            this.getTableData();
        },
        changePageSize(pageSize) {
            this.queryObj.pageSize = pageSize;
            this.getTableData();
        },


        statisticsHandle() {
            this.tjloading= true
            let condition = []
            for (let i in this.ruleForm) {

                if (this.ruleForm[i]) {
                    condition.push(i)
                }
            }

            if (condition.length <= 0) {
                this.$message.error('请选择统计类型！')
                 this.tjloading = false
                return false
            }
            // let condition = []
            let params = {
                condition: condition.join(','),
                qylx_dm: 11,
                sfzb: 'N'
            }
            console.log(params)

            statistics(params).then(res => {
                this.tjloading= false
                this.tjtableData = res.data
                console.log(res)
            })
        },
        resetRuleForm() {
            for (let key in this.ruleForm) {
                this.ruleForm[key] = false;
            }
            this.tjtableData = []
        },
        switchHandle() {
            this.showFlag = !this.showFlag
            for (let key in this.ruleForm) {
                this.ruleForm[key] = false;
            }
            this.tjtableData = []
        },
        exportDataHandle() {
            let params = {
                nsrmc: this.queryObj.nsrmc,
                nsrsbh: this.queryObj.nsrsbh,
                nsrzt: this.queryObj.nsrzt,
                hyml_mc: this.queryObj.hyml_mc,
                hydl_mc: this.queryObj.hydl_mc,
                hyzl_mc: this.queryObj.hyzl_mc,
                hyxl_mc: this.queryObj.hyxl_mc,
                sfjw: this.queryObj.sfjw,
                sssf: this.queryObj.sssf,
                ssds: this.queryObj.ssds,
                zgswjg_dm: this.queryObj.zgswjg_dm,
                pageNum: this.queryObj.pageNo,
                pageSize: this.queryObj.pageSize,
                qylx_dm: 11,
                sfzb: 'N'
            }
            exportData(params).then(res => {




                const elink = document.createElement("a");
                elink.download = localStorage.getItem('jmFileName') || '千户集团成员企业名单.xlsx';
                elink.style.display = "none";
                elink.href = URL.createObjectURL(res);
                document.body.appendChild(elink);
                elink.click();
                URL.revokeObjectURL(elink.href); // 释放URL 对象
                document.body.removeChild(elink);
            })

        },
        currIndex(index) {
            return index + 1;
        },
    }
}
</script>

<style lang="scss" scoped>
.dashboard-container {
    width: 100%;
    min-height: 100%;
    background-color: #fff;
    padding: 8px;
    .btn {
        padding: 0 0 8px 0;
    }
}
// .container {
//     height: 100%;
//     width: 100%;
//     background-color: #fff;
//     .searchMy {
//         padding: 8px;
//         .searchMy-form {
//             height: 28px;
//         }
//     }
// }
</style>
